/*
 * HttpBaseHeader.cpp
 *
 *  Created on: 09.12.2012
 *      Author: zheka
 */

#include "HttpBaseHeader.hpp"
#include "HttpConstants.hpp"
#include <sstream>
#include "util/ProxyException.hpp"
void HttpBaseHeader::setHttpVersion(const std::string & httpVersion) {
	this->httpVersion = httpVersion;
}
void HttpBaseHeader::addHeader(const std::string & key,
		const std::string & value) {
	// TODO: add support chunk transfer
//if(key=="Transfer-Encoding"&&value=="chunked") {
//	throw ProxyException("chunked!!");
//}
	headers[key] = value;
}
std::string HttpBaseHeader::toString() const {
	std::stringstream out;


	for (std::map<std::string, std::string>::const_iterator it = headers.begin();
			it != headers.end(); ++it) {
		out << it->first << HttpConstants::HTTP_HEADER_DELIMITER << " " << it->second
				<< HttpConstants::HTTP_NEWLINE;
	}



	return out.str();
}
